load("@rules_java//java:defs.bzl", "java_binary", "java_library")
load("//tools/bzl:java.bzl", "java_library2")
load("//tools/bzl:javadoc.bzl", "java_doc")

FUNCTION_SRCS = [
    "testsuite/ThrowingConsumer.java",
    "testsuite/ThrowingFunction.java",
]

java_library(
    name = "lib",
    testonly = True,
    resource_strip_prefix = "resources",
    resources = ["//resources/com/google/gerrit/acceptance"],
    visibility = ["//visibility:public"],
    exports = [
        ":framework-lib",
        "//java/com/google/gerrit/common:annotations",
        "//java/com/google/gerrit/common:server",
        "//java/com/google/gerrit/entities",
        "//java/com/google/gerrit/extensions:api",
        "//java/com/google/gerrit/extensions/common/testing:common-test-util",
        "//java/com/google/gerrit/extensions/restapi/testing:restapi-test-util",
        "//java/com/google/gerrit/git",
        "//java/com/google/gerrit/git/testing",
        "//java/com/google/gerrit/gpg/testing:gpg-test-util",
        "//java/com/google/gerrit/httpd",
        "//java/com/google/gerrit/index",
        "//java/com/google/gerrit/json",
        "//java/com/google/gerrit/launcher",
        "//java/com/google/gerrit/lucene",
        "//java/com/google/gerrit/mail",
        "//java/com/google/gerrit/metrics",
        "//java/com/google/gerrit/pgm",
        "//java/com/google/gerrit/pgm/init",
        "//java/com/google/gerrit/pgm/util",
        "//java/com/google/gerrit/server",
        "//java/com/google/gerrit/server/audit",
        "//java/com/google/gerrit/server/git/receive",
        "//java/com/google/gerrit/server/project/testing:project-test-util",
        "//java/com/google/gerrit/server/restapi",
        "//java/com/google/gerrit/sshd",
        "//java/com/google/gerrit/testing:gerrit-test-util",
        "//java/com/google/gerrit/truth",
        "//lib:args4j",
        "//lib:gson",
        "//lib:guava-retrying",
        "//lib:h2",
        "//lib:jgit",
        "//lib:jimfs",
        "//lib:jsch",
        "//lib:servlet-api-without-neverlink",
        "//lib/bouncycastle:bcpg",
        "//lib/bouncycastle:bcprov",
        "//lib/commons:compress",
        "//lib/flogger:api",
        "//lib/guice",
        "//lib/guice:guice-assistedinject",
        "//lib/guice:guice-servlet",
        "//lib/mina:sshd",
        "//prolog:gerrit-prolog-common",
    ],
)

java_binary(
    name = "framework",
    testonly = True,
    main_class = "Dummy",
    visibility = ["//visibility:public"],
    runtime_deps = [":framework-lib"],
)

java_library2(
    name = "framework-lib",
    testonly = True,
    srcs = glob(
        ["**/*.java"],
        exclude = FUNCTION_SRCS,
    ),
    exported_deps = [
        ":function",
        "//java/com/google/gerrit/acceptance/config",
        "//java/com/google/gerrit/acceptance/testsuite/project",
        "//java/com/google/gerrit/exceptions",
        "//java/com/google/gerrit/gpg",
        "//java/com/google/gerrit/httpd/auth/openid",
        "//java/com/google/gerrit/index:query_exception",
        "//java/com/google/gerrit/launcher",
        "//java/com/google/gerrit/lifecycle",
        "//java/com/google/gerrit/pgm:daemon",
        "//java/com/google/gerrit/pgm/http/jetty",
        "//java/com/google/gerrit/pgm/util",
        "//java/com/google/gerrit/server/group/testing",
        "//java/com/google/gerrit/server/project/testing:project-test-util",
        "//java/com/google/gerrit/testing:gerrit-test-util",
        "//lib:guava",
        "//lib:jgit-junit",
        "//lib:jimfs",
        "//lib/auto:auto-value",
        "//lib/auto:auto-value-annotations",
        "//lib/httpcomponents:fluent-hc",
        "//lib/httpcomponents:httpclient",
        "//lib/httpcomponents:httpcore",
        "//lib/jetty:servlet",
        "//lib/log:impl-log4j",
        "//lib/log:log4j",
        "//lib/mockito",
        "//lib/truth",
        "//lib/truth:truth-java8-extension",
        "//prolog:gerrit-prolog-common",
    ],
    visibility = ["//visibility:public"],
    deps = [
        "//java/com/google/gerrit/common:annotations",
        "//java/com/google/gerrit/common:server",
        "//java/com/google/gerrit/entities",
        "//java/com/google/gerrit/extensions:api",
        "//java/com/google/gerrit/httpd",
        "//java/com/google/gerrit/index",
        "//java/com/google/gerrit/index/project",
        "//java/com/google/gerrit/json",
        "//java/com/google/gerrit/lucene",
        "//java/com/google/gerrit/mail",
        "//java/com/google/gerrit/metrics",
        "//java/com/google/gerrit/server",
        "//java/com/google/gerrit/server/audit",
        "//java/com/google/gerrit/server/git/receive",
        "//java/com/google/gerrit/server/logging",
        "//java/com/google/gerrit/server/restapi",
        "//java/com/google/gerrit/server/schema",
        "//java/com/google/gerrit/server/util/git",
        "//java/com/google/gerrit/server/util/time",
        "//java/com/google/gerrit/sshd",
        "//lib:args4j",
        "//lib:gson",
        "//lib:guava-retrying",
        "//lib:jgit",
        "//lib:jsch",
        "//lib:servlet-api",
        "//lib/commons:lang",
        "//lib/greenmail",
        "//lib/guice",
        "//lib/guice:guice-assistedinject",
        "//lib/guice:guice-servlet",
        "//lib/mail",
        "//lib/mina:sshd",
    ],
)

java_library(
    name = "function",
    srcs = FUNCTION_SRCS,
    visibility = ["//visibility:public"],
)

java_doc(
    name = "framework-javadoc",
    testonly = True,
    libs = [":framework-lib"],
    pkgs = ["com.google.gerrit.acceptance"],
    title = "Gerrit Acceptance Test Framework Documentation",
    visibility = ["//visibility:public"],
)
